def count_chars_and_digits():
    """统计字符串中各个字母和数字出现次数"""
    input_str = input("请输入一个字符串（以回车结束）：")

    # 初始化统计字典
    count_dict = {}

    for char in input_str:
        if char.isalpha():  # 如果是字母
            lower_char = char.lower()  # 统一转为小写统计
            count_dict[lower_char] = count_dict.get(lower_char, 0) + 1
        elif char.isdigit():  # 如果是数字
            count_dict[char] = count_dict.get(char, 0) + 1

    # 按字符ASCII码顺序排序输出
    print("\n统计结果：")
    for key in sorted(count_dict.keys()):
        print(f"'{key}': {count_dict[key]}")

def count_letters_and_digits():
    """统计字符串中字母和数字的总数量"""
    input_str = input("请输入一个字符串（以回车结束）：").strip()  # 获取一次输入并去除首尾空白字符
    letter_count = 0
    digit_count = 0

    for char in input_str:
        if char.isalpha():  # 统计字母
            letter_count += 1
        elif char.isdigit():  # 统计数字
            digit_count += 1

    print(f"字母数量: {letter_count}, 数字数量: {digit_count}")

if __name__ == "__main__":
    print("字符统计程序")
    print("------------")
    count_chars_and_digits()
    #count_letters_and_digits()
